﻿@using SDCloudSolution.SDCloud.Web.Utils
@using SDCloudSolution.SDCloud.Web.Models
@model SDCloudSolution.SDCloud.Web.Models.ModelRun.ModelRunListViewModel

@{
    Layout = "~/Views/Shared/_AuthorizedLayout.cshtml";
    ViewBag.Title = "Model runs list";
}

<h1>
    My model run history
</h1>

@if (Model.Items.Count > 0)
{
    <table>
        <thead class="oj-table-header">
            <tr class="oj-table-header-row">
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            #
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Model
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Queued
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Time
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Status
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Model History
                        </div>
                    </div>
                </th>
                <th class="oj-table-column-header-cell">
                    <div class="oj-table-column-header">
                        <div class="oj-table-column-header-text">
                            Download results
                        </div>
                    </div>
                </th>
            </tr>
        </thead>
        @foreach (var item in Model.Items)
        {
            <tbody class="oj-table-body">
                <tr class="oj-table-body-row oj-table-hgrid-lines">
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        @item.ModelRunId
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        @Html.ActionLink(item.ModelName, MVC.ModelRuns.View(item.ModelRunId), new { title = "View details..." })
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        @item.QuequedDate
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        @item.ElapsedTime
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        <span class="label label-@item.StatusType.ToCssClass()">
                            @item.StatusTitle
                        </span>
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        <a href="@Url.Action(MVC.ModelRuns.ListForModel(item.ModelId, null))" class="btn btn-default btn-xs" title="Apply filter for this model">
                            <span class="fa fa-filter"></span>
                        </a>
                    </td>
                    <td class="oj-table-data-cell oj-form-control-inherit">
                        @if (item.StatusType.Equals(StatusViewModel.Success))
                        {
                            <span>
                                <a href="@Url.Action(MVC.ModelRuns.DownloadAsJson(item.ModelRunId))" target="_blank">
                                    .json
                                </a> |
                                <a href = "@Url.Action(MVC.ModelRuns.DownloadAsCsv(item.ModelRunId))" target = "_blank">
                                    .csv
                                </a>
                            </span>
                        }
                    </td>
                </tr>
            </tbody>
        }
    </table>
}
else
{
    <div class="oj-panel oj-margin oj-panel-shadow-md">
        <p>
            We don't have any model run in SDCloud
        </p>
    </div>
}


